package com.config;


import cn.dev33.satoken.stp.StpInterface;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.mapper.UserMapper;
import com.po.User;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

@Component    // 打开此注解，保证此类被springboot扫描，即可完成sa-token的自定义权限验证扩展
@Slf4j
@RequiredArgsConstructor
public class StpInterfaceImpl implements StpInterface {
	private final UserMapper userMapper;


	/**
	 * 返回一个账号所拥有的权限码集合
	 */
	@Override
	public List<String> getPermissionList(Object loginId, String loginType) {
		log.info("执行");
		// 本list仅做模拟，实际项目中要根据具体业务逻辑来查询权限
		List<String> list = new ArrayList<String>();
		LambdaQueryWrapper<User> eq = new LambdaQueryWrapper<User>()
				.eq(User::getId, loginId);

		User user = userMapper.selectOne(eq);
		Long isAdmin = user.getIsAdmin();
		if (isAdmin==1){
			//商家
			list.add("user::admin");
		}else if(isAdmin==2){
			list.add("user::master");
		}

		//list.add("admin.*");
		return list;
	}
 
	/**
	 * 返回一个账号所拥有的角色标识集合 
	 */
	@Override
	public List<String> getRoleList(Object loginId, String loginType) {
		// 本list仅做模拟，实际项目中要根据具体业务逻辑来查询角色
//		log.info("loginid:{}",loginId);
		List<String> list = new ArrayList<String>();
//		LambdaQueryWrapper<User>lambdaQueryWrapper=new LambdaQueryWrapper<User>();
//		lambdaQueryWrapper.eq(User::getId,loginId).eq(User::getIsAdmin,1);
//		User user=userMapper.selectOne(lambdaQueryWrapper);

//		if (ObjectUtil.isNotEmpty(user)){
//			//
//		}

		return list;
	}
 
}